#!/bin/bash

source ../../common/common.sh

echo "===INIT==UBUNTU=IDEA=IDE==="
sudo echo "SUDO ROOT"


if [ `is_desktop` -eq 1 ]; then
  tmpdir=/works/downloads/idea
  tmpfile=$tmpdir/pycharm-professional-3.4.1.tar.gz
  url=http://download-ln.jetbrains.com/python/pycharm-professional-3.4.1.tar.gz
  optdir=/opt
  optDevelopDir=$optdir/developsoft
  optPycharmDir=pycharm-3.4.1
  optPycharmDirLN=pycharm

  show t "安装Jetbrains 的 PyCharm 3.4.1"
  show i "下载idea PyCharm 安装文件"
  chk_mkdir $tmpdir
  chk_downfile $url $tmpfile yes

  if [ -f $tmpfile ]; then
    show s "Download $tmpfile OK."

    chk_mkdir $optDevelopDir sudo

    if [ ! -d $optDevelopDir/$optPycharmDir ]; then
      show s "解压下载文件"
      sudo tar zxvf $tmpfile -C $optDevelopDir
    fi

    pwddir=`pwd`
    cd $optDevelopDir

    if [ -d $optDevelopDir/$optPycharmDir ]; then
      if [ -L $optPycharmDirLN ]; then rm -rf $optPycharmDirLN; fi
      ln -s $optPycharmDir $optPycharmDirLN
    fi
    cd $pwddir

    show i "附加用户路径"

    chk_addpath 2 PYTHON_PYCHARM_PATH $optDevelopDir/$optPycharmDirLN/bin
  fi
  #chk_addpath 2 PYTHON_PYCHARM_PATH $optDevelopDir/$optPycharmDirLN/bin
fi

